"use strict";

/**
 * @ngdoc service
 * @name jgappApp.logList
 * @description
 * # logList
 * Service in the jgappApp.
 */
angular.module("jgappApp").service("logList", function($q, $http, openApi) {
  // AngularJS will instantiate a singleton by calling "new" on this function
  var logList = {};
  logList.getData = function(options) {
    var defer = $q.defer();
    $http
      .get(options.url, {
        params: options.param
      })
      .then(function(data, status, headers, config) {
        data = data.data;
        if (data.logout) {
          // Util.logout();
          return;
        }
        if (data.success) {
          defer.resolve(logList.getClassKey(data));
        }
      });
    return defer.promise;
  };
  logList.getClassKey = function(data) {
    data.result.forEach(function(item, index) {
      var className = "process-agree"; //默认绿色
      var a, b, c, d, e, f;
      a = "办理中";
      b = "不同意";
      c = "同意";
      d = "驳回";
      e = "提交审批";
      f = "未开始";
      switch (item.operationResult) {
        case a:
          className = "process-ing";
          break;
        case b:
          className = "process-disagree";
          break;
        case c:
          className = "process-agree";
          break;
        case d:
          className = "process-reject";
          break;
        case e:
          className = "process-start";
          break;
        case f:
          className = "process-default";
          break;

        default:
          break;
      }
      item.className=className
    });
    return data.result;
  };
  return logList;
});
